<?php
/**
 * 微信公众号用户model
 * User: daxia
 * Date: 2020/10/14
 * Time: 22:51
 */

namespace app\api\model;

use think\Db;
use think\Log;
use think\Model;

class WxUser extends Model
{

    protected $name = 'user_wx';

    /**
     * @param array $condition
     * @param int $isLock
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function findInfoByCondition($condition = [], $isLock = 0)
    {
        if ($isLock == 1) {
            $user = self::where($condition)->lock(true)->find();
        } else {
            $user = self::where($condition)->find();
        }
        return $user ? $user : [];
    }

    public function saveById($id, $data)
    {
        if ($id && $data) {
            $data['updatetime'] = time();
            return self::where(['id' => $id])->update($data);
        }
        return 0;
    }

    public function addRecord($addData)
    {
        if ($addData) {
            $addData['createtime'] = time();
            $addData['updatetime'] = time();
            return self::create($addData);
        }
        return null;
    }

}